package main

import "saasems/models"

var tenantAlertRules = make(map[string][]models.AlertRule)

func AddAlertRule(tenantID string, rule models.AlertRule) {
	rules := tenantAlertRules[tenantID]
	rules = append(rules, rule)
	tenantAlertRules[tenantID] = rules
}

func GetAlertRules(tenantID string) []models.AlertRule {
	return tenantAlertRules[tenantID]
}

func CheckThreshold(metricValue float64, rule models.AlertRule) bool {
	switch rule.Condition {
	case ">":
		return metricValue > rule.Threshold
	case "<":
		return metricValue < rule.Threshold
	case ">=":
		return metricValue >= rule.Threshold
	case "<=":
		return metricValue <= rule.Threshold
	default:
		return false
	}
}
